{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ROS Robot Demo\n",
    "\n",
    "Note: you need to preprocess the pr2 description to convert the textures from `.tif` to `.png`. \n",
    "As described here under 1.3: http://wiki.ros.org/ros3djs/Tutorials/VisualizingAURDF#Converting_URDFs_to_use_PNG_images\n",
    "\n",
    "Easiest using the following two commands (NOTE: use with caution!)\n",
    "\n",
    "```\n",
    "cd /opt/ros/kinetic/share/pr2_description/\n",
    "sudo sh -c 'for i in `find . -type f -name \"*.tif\"`; do convert \"$i\" \"${i%.*}.png\"; done;'\n",
    "sudo sed -i -e 's/tif/png/g' **/*.dae\n",
    "```\n",
    "\n",
    "Also, you'll need `http\n",
    "\n",
    "Run\n",
    "\n",
    "`roslaunch pr2_description upload_pr2.launch`\n",
    "\n",
    "`roslaunch {NOTEBOOK FOLDER}/launch/robo.launch`\n",
    "\n",
    "http-server from `npm`: `npm install -g http-server` (or any other http server that supports CORS)\n",
    "\n",
    "`http-server /opt/ros/kinetic/share/ -p 3000 --cors`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ros3d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "v = ros3d.Viewer()\n",
    "rc = ros3d.ROSConnection()\n",
    "tf_client = ros3d.TFClient(ros=rc, fixed_frame='/base_link')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2fade6ea09b24866a6545e9c73d7a3f5",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Viewer()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "g = ros3d.GridModel()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "urdf = ros3d.URDFModel(ros=rc, tf_client=tf_client, path='http://localhost:3000/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "v.objects = [g, urdf]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "v.height = '500px'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
